/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author corneliugosa
 */
@Entity
@Table(name = "subject_matter")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "SubjectMatter.findAll", query = "SELECT s FROM SubjectMatter s"),
    @NamedQuery(name = "SubjectMatter.findById", query = "SELECT s FROM SubjectMatter s WHERE s.id = :id"),
    @NamedQuery(name = "SubjectMatter.findByClassAndProf", query = "SELECT sm "
                                                                       + " FROM SubjectMatter sm "
                                                                       + " JOIN sm.linkProfessorList lp "
                                                                       + " JOIN lp.idPerson pers "
                                                                       + " JOIN pers.personToClassList ptc "
                                                                    + " WHERE pers = :proffessor "
                                                                       + " AND ptc.cls.number = :cls ")
})

public class SubjectMatter implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 65535)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 65535)
    @Column(name = "description")
    private String description;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idSubjectMatter")
    private List<Timetable> timetableList;
    @JoinColumn(name = "id_exam_type", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private ExamType idExamType;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idSubjectMatter")
    private List<Catalogue> catalogueList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idSubjectMatter")
    private List<Homework> homeworkList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "subjectMatter")
    private List<Exams> examsList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idSubjectMatter")
    private List<LinkProfessor> linkProfessorList;

    public SubjectMatter() {
    }

    public SubjectMatter(Integer id) {
        this.id = id;
    }

    public SubjectMatter(Integer id, String name, String description) {
        this.id = id;
        this.name = name;
        this.description = description;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @XmlTransient
    public List<Timetable> getTimetableList() {
        return timetableList;
    }

    public void setTimetableList(List<Timetable> timetableList) {
        this.timetableList = timetableList;
    }

    public ExamType getIdExamType() {
        return idExamType;
    }

    public void setIdExamType(ExamType idExamType) {
        this.idExamType = idExamType;
    }

    @XmlTransient
    public List<Catalogue> getCatalogueList() {
        return catalogueList;
    }

    public void setCatalogueList(List<Catalogue> catalogueList) {
        this.catalogueList = catalogueList;
    }

    @XmlTransient
    public List<Homework> getHomeworkList() {
        return homeworkList;
    }

    public void setHomeworkList(List<Homework> homeworkList) {
        this.homeworkList = homeworkList;
    }

    @XmlTransient
    public List<Exams> getExamsList() {
        return examsList;
    }

    public void setExamsList(List<Exams> examsList) {
        this.examsList = examsList;
    }

    @XmlTransient
    public List<LinkProfessor> getLinkProfessorList() {
        return linkProfessorList;
    }

    public void setLinkProfessorList(List<LinkProfessor> linkProfessorList) {
        this.linkProfessorList = linkProfessorList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SubjectMatter)) {
            return false;
        }
        SubjectMatter other = (SubjectMatter) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.SubjectMatter[ id=" + id + " ]";
    }
    
}
